package MyBatis;

import java.util.Map;
import java.util.List;

public class UserSqlProvider {
    public String updateUser(Map<String, Object> params) {
        StringBuilder sql = new StringBuilder("UPDATE users SET ");
        boolean first = true;
        if (params.containsKey("name") && params.get("name") != null) {
            if (!first) {
                sql.append(", ");
            }
            sql.append("name = #{name}");
            first = false;
        }
        if (params.containsKey("age") && params.get("age") != null) {
            if (!first) {
                sql.append(", ");
            }
            sql.append("age = #{age}");
        }
        sql.append(" WHERE id = #{id}");
        return sql.toString();
    }
    public String deleteUsers(List<Integer> ids) {
        StringBuilder sql = new StringBuilder("DELETE FROM users WHERE id IN (");
        for (int i = 0; i < ids.size(); i++) {
            if (i > 0) {
                sql.append(", ");
            }
            sql.append("#{list[").append(i).append("]}");
        }
        sql.append(")");
        return sql.toString();
    }
}